import showLog from "../../backlog/showLog.vue"
import Bus from "../bus.js"
import back from "../../../component/goback/index.vue"
export default {
  name: 'FeedbackDetails',
  data() {
    return {
      opinionid: "",
      list: "",
      current: this.$route.query.current,
      backlogReport: this.$route.query.backlogReport || false,
      logReport: this.$route.query.logReport || false,
      reportid: this.$route.query.reportid || "",
      replyInputShow: false,
      replyTextShow: false,
      warnDialogVisible: false,
      form: {
        pagenum: "1", //查询页码
        opinionid: "", //意见建议编码
        username: "", //建议人名称
        telnum: "", //投诉人电话
        content: "", //投诉内容
        pagesize: 1, //页码大小
        totalnum: "10", //搜索总数
        createtime: "" //投诉时间
      },
      reportContent: "", //上报原因
      picture: [], //图片
      toReplyData: {
        content: "",
        type: "", //1-回复   2-忽略
        opinionid: this.$route.query.opinionid //意见建议编码
      },
      replytime: "", //回复时间
      global: {},
      showLog: false,
      imaDialogVisible: false,
      imgurl: "",
      currentType: this.$route.query.currentType || ""
    }
  },
  components: {
    showLog,
    back
  },
  created() {
    this.global = this.GLOBAL
    // this.geteData()
    this.geteData()
  },
  activated() {
    // console.log(123123)
  },
  methods: {
    goBack(){
      this.$router.back()
    },
    edit() {
      this.$router.push({
        path: "/home/editor",
        query: {
          type: "editor"
        }
      })
    },

    bus() {
      Bus.$emit("onload")
    },

    geteData() {
      this.$axios
        .$post("app/v1/platform/option/detail", {
          opinionid: this.$route.query.opinionid
        })
        .then(res => {
          this.picture = []
          this.form = res.data.data
          this.picture.push(
            res.data.data.picture1 || "",
            res.data.data.picture2 || "",
            res.data.data.picture3 || ""
          )
          if (res.data.data.replycontent) {
            this.replyTextShow = true
            this.toReplyData.content = res.data.data.replycontent
            this.replytime = res.data.data.replytime
          }
        })
    },
    ReplyAjax() {
      this.$axios
        .$post("/app/v1/platform/option/replySubmit", this.toReplyData)
        .then(res => {
          if (res.data.code == 1 && this.toReplyData.type == 1) {
            //回复
            this.replyInputShow = false
            this.replyTextShow = tru
            this.bus()
            this.geteData()
          } else if (res.data.code == 1 && this.toReplyData.type == 2) {
            this.$router.go(-1)
          } else {
            this.replyInputShow = false
            this.$message({
              message: res.data.message,
              type: "warning"
            })
          }
        })
        .catch(() => {})
    },

    //待办提交
    reportCall(data) {
      this.$axios
        .post("app/v1/platform/unusual/todoHandleSubmit", data)
        .then(resp => {
          if (resp.data.message === "success.") {
            this.warnDialogVisible = false
            this.replyInputShow = false
            this.replyTextShow = false
            this.loading = false
            this.$message({
              message: "上报成功",
              type: "success"
            })
          } else {
            this.replyInputShow = false
            this.replyTextShow = false
            this.warnDialogVisible = false
            this.$message({
              message: resp.data.message,
              type: "error"
            })
          }
        })
    },
    //回复
    toReply() {
      this.replyInputShow = true
      this.toReplyData.type = 1
    },
    //忽略
    toIgnore() {
      this.$confirm(`确定忽略吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.toReplyData.type = 2
          this.replyInputShow = false
          this.ReplyAjax()
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          })
        })
    },

    //上报
    toReport(r, type) {
      this.warnDialogVisible = true
    },

    closeWarnDialog() {
      this.reportContent = ""
    },

    //上报请求
    reportAjax() {
      let data = {
        id: this.toReplyData.opinionid, //意见建议编码
        reporttype: 7,
        content: this.reportContent
      }
      if (!this.reportContent) {
        this.$message({
          type: "warning",
          message: "上报内容不能为空!"
        })
        return
      }
      this.$axios
        .post("/app/v1/platform/unusual/reportSubmit", data)
        .then(res => {
          if (res.data.message === "success.") {
            this.warnDialogVisible = false
            this.$message({
              type: "success",
              message: "操作成功!"
            })
            // this.replyTextShow = true
          } else {
            this.warnDialogVisible = false
            this.$message({
              message: res.data.message,
              type: "error"
            })
          }
        })
    },
    //上报里确定
    confirmReport() {
      if (!this.backlogReport) {
        this.reportAjax()
      } else {
        if (!this.reportContent) {
          this.$message({
            type: "warning",
            message: "上报内容不能为空!"
          })
          return
        }
        let currentData = {
          reportid: this.reportid,
          status: 0,
          content: this.reportContent
        }
        this.reportCall(currentData)
      }
    },

    onSubmit() {
      this.loading = true
      this.ReplyAjax()
    },
    lookLog() {
      this.showLog = true
    },
    isShowImg(url) {
      this.imaDialogVisible = true
      this.imgurl = url
    }
  }
}
